/**
 * All Rights Reserved , Copyright (C) 2020 , 青岛鼎信通讯股份有限公司
 * <p>
 * PmDelayApplyService
 * 项目延期申请
 * <p>
 * 修改纪录
 * 2020-05-23 版本：1.0 wushenghong 创建。
 *
 * @version 版本：1.0
 * @author 作者：wushenghong
 * 创建日期：2020-05-23
 */
package com.topscomm.pm.service.impl;

import com.topscomm.basic.BasicEntity;
import com.topscomm.basic.util.PrimaryKeyUtil;
import com.topscomm.pm.pojo.PmDelayApplyEntity;
import com.topscomm.pm.service.IPmCalendarService;
import com.topscomm.pm.service.IPmDelayApplyService;
import com.topscomm.pm.service.IPmProjectService;
import com.topscomm.pm.service.impl.auto.PmDelayApplyServiceAuto;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service(value = "pmDelayApplyService")
@Scope(value = "singleton")
public class PmDelayApplyService extends PmDelayApplyServiceAuto implements IPmDelayApplyService {
    @Resource(name = "pmProjectService")
    private IPmProjectService pmProjectService;
    @Resource(name = "pmCalendarService")
    private IPmCalendarService pmCalendarService;

    /**
     * @param entity
     * @throws
     * @author: wushenghong
     * @date: 2020-05-23
     * @description:单号生成
     * @modify:
     */
    @Override
    protected void beforeInsert(BasicEntity entity) {
        super.beforeInsert(entity);
        if (entity.getId() <= 0) {// 赋值Id和单号
            long[] arrayId = PrimaryKeyUtil.GeneIDs(entity.getTableName(), 1);
            entity.setId(arrayId[0]);
            String docNo = String.valueOf(arrayId[0]);
            docNo = docNo.substring(0, 6) + docNo.substring(9);
            entity.setValue(PmDelayApplyEntity.FieldDocno, docNo);
        }
    }

    /**
     * @param
     * @throws
     * @author: wushenghong
     * @date: 2020-05-16
     * @description:审批通过后，将延期时间更新至项目档案，并生成项目日历
     * @modify:
     */
//    @Override
//    @Transactional
//    protected void afterApprove(TapEntity billEntity, CboApprovalNodeInsEntity nodeIns, CboApprovalNodeEntity node, SessionUserBean sessionUserBean) {
//        super.afterApprove(billEntity, nodeIns, node, sessionUserBean);
//        PmDelayApplyEntity pmDelayApplyEntity = (PmDelayApplyEntity) billEntity;
//        int state = pmDelayApplyEntity.getState();//单据状态
//        long projectId = pmDelayApplyEntity.getProjectid();//项目id
//        Date nowPlanEndTime = pmDelayApplyEntity.getEndtime();//新的完工时间
//        PmProjectEntity pmProjectEntity = pmProjectService.queryById(ConvertUtil.convertToString(projectId));
//        Date oldPlanEndTime = pmProjectEntity == null ? null : pmProjectEntity.getPlanendtime();//原计划完工时间
//        String projectCode = pmProjectEntity == null ? "" : pmProjectEntity.getCode();//项目号
//        Map map = new HashMap();
//        if (9 == state) {
//            if (pmProjectEntity != null) {
//                // 更新项目计划完工时间
//                pmProjectEntity.setPlanendtime(nowPlanEndTime);
//                pmProjectService.updateEntity(pmProjectEntity);
//            }
//            // 同时更新项目日历
//            map.put("projectid", projectId);
//            map.put("projectcode", projectCode);
//            map.put("starttime", oldPlanEndTime);
//            map.put("endtime", nowPlanEndTime);
//            pmCalendarService.insertBatchCalendar(map);
//        }
//    }
}